package com.xjscrm.console.service.customer.list.impl;

import com.xjscrm.common.constant.ResponseMsg;
import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.common.result.ResponseCode;
import com.xjscrm.console.param.list.BatchDeleListDto;
import com.xjscrm.console.param.list.WwCustomerBlackDto;
import com.xjscrm.console.param.list.WwCustomerWhiteDto;
import com.xjscrm.console.service.customer.list.BatchListService;
import com.xjscrm.console.service.customer.list.BlackListService;
import com.xjscrm.console.service.customer.list.WhiteListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BatchListServiceImpl implements BatchListService {

    @Autowired
    private BlackListService blackListService;

    @Autowired
    private WhiteListService whiteListService;
    @Override
    public void batchDeleBlackList(BatchDeleListDto batchDeleListDto) {

        if(batchDeleListDto.getIds()==null||batchDeleListDto.getIds().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        for (Long id:batchDeleListDto.getIds()) {
            try {
                batchDeleListDto.setId(id);
                blackListService.deleBlackList(batchDeleListDto);
            }catch (Exception e){
              e.printStackTrace();
            }
        }

    }

    @Override
    public void batchDeleWhiteList(BatchDeleListDto batchDeleListDto) {
        if(batchDeleListDto.getIds()==null||batchDeleListDto.getIds().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        for (Long id:batchDeleListDto.getIds()) {
            try {
                batchDeleListDto.setId(id);
                whiteListService.deleBlackList(batchDeleListDto);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    @Override
    public void addBlackList(WwCustomerBlackDto wwCustomerBlackDto) {
        if(wwCustomerBlackDto.getWxids()==null||wwCustomerBlackDto.getWxids().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        for (String wxid:wwCustomerBlackDto.getWxids()) {
            try {
                wwCustomerBlackDto.setWxid(wxid);
                blackListService.addBlackList(wwCustomerBlackDto);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    @Override
    public void addWhileList(WwCustomerWhiteDto wwCustomerWhiteDto) {
        if(wwCustomerWhiteDto.getWxids()==null||wwCustomerWhiteDto.getWxids().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        for (String wxid:wwCustomerWhiteDto.getWxids()) {
            try {
                wwCustomerWhiteDto.setWxid(wxid);
                whiteListService.addWhileList(wwCustomerWhiteDto);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
